/**
 * 
 */
package com.dongnam.quanly.web.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * @author long.pham
 * 
 */
public class DateFormatUtil {

	private static DateFormat formatter;
	private static Locale defaultLocale = Locale.ENGLISH;
	private static String patternDefault = "yyyyMMdd";
	private static String patternMonth = "yyyyMM";

	/**
	 * Convert date to string
	 * 
	 * @param date
	 * @return String
	 */
	public static String Date2String(String pattern, Date date) {
		formatter = new SimpleDateFormat(pattern, defaultLocale);
		return formatter.format(date);
	}

	/**
	 * Convert string to date with specified pattern
	 * 
	 * @param pattern
	 * @param str
	 * @return date
	 */
	public static Date String2Date(String pattern, String str) {
		formatter = new SimpleDateFormat(pattern, defaultLocale);
		Date date = null;
		try {
			date = formatter.parse(str);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			date = null;
		}
		return date;
	}

	public static String getPattern() {
		return patternDefault;
	}

	public static String getPatternMonth() {
		return patternMonth;
	}

	public static String Date2String(Date date) {
		formatter = new SimpleDateFormat(patternDefault, defaultLocale);
		return formatter.format(date);
	}
}
